package com.edu.publisher.controller;

import com.edu.publisher.service.OrderUserService;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;

//下单用户controller
@RestController
public class OrderUserController {
    @Autowired
    private OrderUserService orderUserService;
    @RequestMapping("/oum")
    public String getOUM(@RequestParam(value = "date", defaultValue = "0") Integer date){
        if (date == 0) {
            date = now();
        }
        BigDecimal gmv = orderUserService.getOUM(date);
        String json = "{\"status\": 0,\"data\": " + gmv + "}";
        return json;
    }
    private Integer now() {
        String yyyyMMdd = DateFormatUtils.format(new Date(), "yyyyMMdd");
        return Integer.valueOf(yyyyMMdd);
    }
}
